<?php
/**
 * API返回状态码定义
 * 
 * @copyright 139.com Inc
 * 
 */

class ApiErr {

	//系统信息
	const API_EC_SUCCESS = 0;
	const API_EC_PARAM = 100;//参数缺失
	const API_EC_PARAM_APP_KEY = 101;//错误的appkey
	const API_EC_PARAM_SIGNATURE = 102;//签名验证失败
	const API_EC_PARAM_AUTHORIZE = 103;//没有进行身份验证
	const API_EC_UNKNOWN_METHOD = 104;//未知的请求方法
	const API_EC_NOT_AUTHORIZED = 105;//认证失败
	const API_EC_SYSERROR = 106;//接口异常错误
	const API_EC_OVER_PAGELIMIT = 107;//超过单页最大数量
	const API_EC_API_SUSPENDED_VISIT = 108;//接口尚未开放或暂时关闭
	const API_EC_API_OVER_REQUESTLIMIT = 109;//超过接口每小时请求次数上限
	const API_EC_APP_PERMISSION_DENIED = 110;//权限不足，无法访问该接口
	const API_EC_APP_FORBIDDEN = 111;//应用被禁止
	const API_EC_EMPTY_TIMESTAMP = 112;//时间戳不能为空
	const API_EC_APP_IPVERIFY_PERMISSION_DENIED = 113;//应用没有使用IP认证的授权
	const API_EC_APP_RESTVERIFY_PERMISSION_DENIED = 114;//应用没有使用后台访问认证的授权
	const API_EC_APP_ACCESS_TOKEN_EXPIRED = 115;//access_token已过期

	//公用错误信息
	const API_EC_NOTEXIST_USER = 100001; //用户不存在
	const API_EC_EMPTY_TARGET_UID = 200003; //目标用户uid不能为空
	const API_EC_EMPTY_UID = 400001;//用户uid不能为空
	const API_EC_EMPTY_MOBILE = 400002;//手机号不能为空
	const API_EC_ERROR_MOBILE = 400003;//手机号码格式不正确
	const API_EC_EMPTY_TARGETIDS = 600001;//目标id不能为空
	const API_EC_PARAM_ERROR	= 400007;//参数错误

	//user error
	const API_EC_USER_SETINFO_FAIL		= 100002; //更新用户资料失败
	const API_EC_USER_SETPIC_FAIL		= 100003; //更新用户头像失败
	const API_EC_USER_EMPTY_PIC			= 100004; //用户头像不能为空
	const API_EC_USER_EMPTY_SCREEN_NAME	= 100005; //screenname不能为空
	const API_EC_USER_EMPTY_PASSWORD	= 100006; //密码不能为空
	const API_EC_USER_EMPTY_NICKNAME	= 100007; //昵称不能为空
	const API_EC_USER_SCREEN_NAME_EXIST	= 100008; //screenname已经存在，注册用户时
	const API_EC_USER_EMPTY_PRIVATE		= 100009; //隐私设置不能为空
	const API_EC_USER_ERROR_CNID		= 100010; //身份证号错误
	const API_EC_USER_ERROR_REAL_NAME 	= 100011; //真实姓名错误
	const API_EC_USER_NICKNAME_VERIFIED = 100012; //昵称已验证,不能修改

	//relationship error
	const API_EC_REL_ADD_FOLLEXIT			= 200001; //好友关系已存在
	const API_EC_REL_RMV_FOLLNOEX			= 200002; //好友关系不存在
	const API_EC_REL_OVER_FOLLOWHOURLIMIT	= 200004; //超出每小时关注用户数量上限
	const API_EC_REL_OVER_FOLLOWDAYLIMIT	= 200005; //超出每天关注用户数量上限
	const API_EC_REL_NOT_FOOLLOW_ME			= 200006; //不能关注自己

	//timeline error
	const API_EC_TIMELINE_NOTEXIS_ITALK = 300001;//说客不存在
	const API_EC_TIMELINE_EMPTY_ID = 300002;//说客id不能为空
	const API_EC_TIMELINE_EMPTY_TEXT = 300003;//说客内容不能为空
	const API_EC_TIMELINE_EMPTY_PIC = 300004;//图片不能为空
	const API_EC_TIMELINE_OVERLIMIT_ITALKIDS = 300005;//批量获取说客信息接口超过数量最大限度
	const API_EC_TIMELINE_CONTENT_OVER140WORDS = 300006;//说客内容超过140个字
	const API_EC_TIMELINE_CONTENT_PROHIBITED = 300007;//说客内容包含违禁词汇
	const API_EC_TIMELINE_PIC_OVER2M = 300008;//图片大小超过2M
	const API_EC_TIMELINE_OVER_POSTTEXTLIMIT = 300009;//超过每小时发送说客条数上限
	const API_EC_TIMELINE_OVER_COMMENTLIMIT = 300010;//超过每小时发送评论条数上限
	const API_EC_TIMELINE_EMPTY_VIDEO = 3000011;//视频资源不能为空
	const API_EC_TIMELINE_NOTREALNAME = 3000012;//未进行实名认证

	//mobile error
	const API_EC_MOBILE_NOTREG = 400004;//未注册的手机号
	const API_EC_MOBILE_NOEXIST_UID = 400005;//不存在的uid
	const API_EC_MOBILE_ALREADY_REGISTER	= 400006;//此手机号已经注册
	const API_EC_MOBILE_NOT_CMNUM	= 400008;//非移动手机号
	const API_EC_MOBILE_SMSTEMPLATE_NOEXIST = 400009;//短信模板不存在

	//search
	const API_EC_SEARCH_EMPTY_TEXT = 500001;//搜索的关键词不能为空

	//cmcc
	const API_EC_CMCC_OVERLIMIT_TARGETIDS = 600002;//超出目标id最大数量限制
	const API_EC_CMCC_ERROR_IDS = 600003;//目标id格式错误或包含不存在的用户id

	//requests
	const API_EC_REL_EMPTY_RECEIVER_ID	= 700001; //接受请求的用户不能为空

	//tinyurl
	const API_EC_TINYURL_EMPTY_TEXT = 101001;//要转换的内容不能为空

	//count
	const API_EC_COUNT_EMPTY_TYPE		= 102001; //统计类型不能为空
	const API_EC_COUNT_EMPTY_KEY		= 102002; //统计数据类型不能为空
	const API_EC_COUNT_EMPTY_DATA_ID	= 102003; //统计数据ID不能为空
	const API_EC_COUNT_EMPTY_VALUE		= 102004; //统计数据值，当type为amount时不能为空

	//lists
	const API_EC_LISTS_EMPTY_NAME		= 103001; //列表名不能为空
	const API_EC_LISTS_GROUP_LIMIT		= 103002; //名单个数超出限制
	const API_EC_LISTS_EXIST_USER_ID	= 103003; //该用户已在名单中
	const API_EC_LISTS_NOT_EXIST_USER	= 103004; //该用户不在名单中
	const API_EC_LISTS_NOT_EXIST		= 103005; //该用户的分组不存在
	const API_EC_LISTS_ALREADY_EXIST    = 12006;  //该分组已存在

	//account
	const API_EC_ACCOUNT_LOGINFAILED	= 104001; //登录验证失败
	const API_EC_ACOUNT_AUTHCODE_FAIL	= 104002; //验证码验证失败
	const API_EC_ACOUNT_LOGIN_BANNED	= 104003; //登录被暂时禁止
	const API_EC_ACOUNT_LIMIT_MMS		= 104004; //调用短信发送达到上限
	const API_EC_ACOUNT_PASSWD_ERROR	= 104005; //密码错误
	const API_EC_ACOUNT_AUTHCODE_ERROR	= 104006; //验证码验证失败（激活、重置密码、换号新号码） 

	//medal
	const API_EC_MEDAL_EMPTY_MEDALID	= 105001; //勋章id不能为空
	const API_EC_MEDAL_AWARDED			= 105002; //用户已经获得过该徽章
	const API_EC_MEDAL_CANT_SUSPEND		= 105003; //该勋章暂时不能悬挂
	

	//状态码描述
	static $api_error_descriptions = array(
		self::API_EC_SUCCESS				=> 'Success',
	
		self::API_EC_PARAM					=> 'Invalid parameter',
		self::API_EC_PARAM_APP_KEY			=> 'Invalid appkey',
		self::API_EC_PARAM_SIGNATURE		=> 'Signature certification failed',
		self::API_EC_PARAM_AUTHORIZE		=> 'No identity verification',
		self::API_EC_UNKNOWN_METHOD      	=> 'Unknown method',
		self::API_EC_NOT_AUTHORIZED     	=> 'Authorized failed',
		self::API_EC_SYSERROR				=> 'Interface invoke exception',
		self::API_EC_OVER_PAGELIMIT			=> 'More than one page maximum number',
		self::API_EC_API_OVER_REQUESTLIMIT 	=> 'More than interface per hour request frequency restrictions',
		self::API_EC_APP_PERMISSION_DENIED 	=> 'Permissions insufficiency cannot access the interface',
		self::API_EC_APP_FORBIDDEN 			=> 'Applications are prohibited',
		self::API_EC_EMPTY_TIMESTAMP		=> 'Timestamp is not empty',
		self::API_EC_APP_IPVERIFY_PERMISSION_DENIED => 'Application does not use this certification authorized',
		self::API_EC_APP_RESTVERIFY_PERMISSION_DENIED => 'Application does not use this certification authorized',
		self::API_EC_APP_ACCESS_TOKEN_EXPIRED => 'Token has expired',

		self::API_EC_NOTEXIST_USER		=> 'The user does not exist',
		self::API_EC_EMPTY_TARGET_UID	=> 'Target users uid can not be empty',
		self::API_EC_EMPTY_UID			=> 'UserId can not be empty',
		self::API_EC_EMPTY_MOBILE		=> 'Mobile number can not be empty',
		self::API_EC_ERROR_MOBILE		=> 'Mobile phone number format is not correct',
		self::API_EC_EMPTY_TARGETIDS 	=> 'Target id can not be empty',
		self::API_EC_PARAM_ERROR		=> 'Parameter error',

		self::API_EC_USER_SETINFO_FAIL		=> 'Failed to update userinfo',
		self::API_EC_USER_SETPIC_FAIL		=> 'Failed to update user avatar picture',
		self::API_EC_USER_EMPTY_SCREEN_NAME	=> 'Screen name can not be empty',
		self::API_EC_USER_EMPTY_PASSWORD	=> 'Password can not be empty',
		self::API_EC_USER_EMPTY_NICKNAME	=> 'Nickname can not be empty',
		self::API_EC_USER_SCREEN_NAME_EXIST	=> 'Screen name already exists',
		self::API_EC_USER_EMPTY_PRIVATE		=> 'Private settings can not be empty',
		self::API_EC_USER_ERROR_CNID 		=> 'Error identity',
		self::API_EC_USER_ERROR_REAL_NAME 	=> 'Error real name',
		self::API_EC_USER_NICKNAME_VERIFIED => 'Nickname have been verified,can not be changed',

		self::API_EC_REL_ADD_FOLLEXIT		=> 'Follow relationship already exists',
		self::API_EC_REL_RMV_FOLLNOEX		=> 'Follow relationship never exists',
		self::API_EC_REL_OVER_FOLLOWHOURLIMIT => 'Over follow user limit(per hour)',
		self::API_EC_REL_OVER_FOLLOWDAYLIMIT => 'Over follow user limit(per day)',
		self::API_EC_REL_NOT_FOOLLOW_ME		=> 'Can not follow yourself',
		
		self::API_EC_TIMELINE_NOTEXIS_ITALK => 'The italk does not exist',
		self::API_EC_TIMELINE_EMPTY_ID		=> 'Id can not be empty',
		self::API_EC_TIMELINE_EMPTY_TEXT	=> 'Text can not be empty',
		self::API_EC_TIMELINE_EMPTY_PIC		=> 'Pic can not be empty',
		self::API_EC_TIMELINE_CONTENT_OVER140WORDS 	=> 'Content length in more than 140 words',
		self::API_EC_TIMELINE_OVERLIMIT_ITALKIDS 	=> 'More than batch utmost',
		self::API_EC_TIMELINE_CONTENT_PROHIBITED 	=> 'The content includes prohibited vocabulary',
		self::API_EC_TIMELINE_PIC_OVER2M 	=> 'Photo size more than 2m',
		self::API_EC_TIMELINE_OVER_POSTTEXTLIMIT => 'More than posttext number per hour the upper limit ',
		self::API_EC_TIMELINE_OVER_COMMENTLIMIT => 'More than comment number per hour the upper limit',
		self::API_EC_TIMELINE_EMPTY_VIDEO => 'Video resources can not be empty',
		self::API_EC_TIMELINE_NOTREALNAME => 'Not real name',

		self::API_EC_MOBILE_NOTREG			=> 'Unregistered mobile phone number',
		self::API_EC_MOBILE_NOEXIST_UID		=> 'Donot exist uid',
		self::API_EC_MOBILE_ALREADY_REGISTER=> 'The phone number is already registered',
		self::API_EC_MOBILE_NOT_CMNUM => 'Not chinamobile phone number',
		self::API_EC_MOBILE_SMSTEMPLATE_NOEXIST	=>'Short message template doesnot exist',

		self::API_EC_SEARCH_EMPTY_TEXT 		=> 'Search keywords can not be empty',

		self::API_EC_API_SUSPENDED_VISIT	=> 'Interface are not yet open or temporarily shut down',

		self::API_EC_CMCC_OVERLIMIT_TARGETIDS => 'Beyond the target id maximum number limit',
		self::API_EC_CMCC_ERROR_IDS => 'Target ids format error or contain does not exist uid',

		self::API_EC_TINYURL_EMPTY_TEXT => 'Want to convert content can not be empty',

		self::API_EC_REL_EMPTY_RECEIVER_ID		=> 'Accepted the request of the user can not be empty',

		self::API_EC_COUNT_EMPTY_TYPE		=> 'Count types can not be empty',
		self::API_EC_COUNT_EMPTY_KEY		=> 'Count data type can not be empty',
		self::API_EC_COUNT_EMPTY_DATA_ID	=> 'Count data type value can not be empty',
		self::API_EC_COUNT_EMPTY_VALUE		=> 'Count data value, when the type can not be empty for the amount',

		self::API_EC_LISTS_EMPTY_NAME		=> 'List name can not be empty',
		self::API_EC_LISTS_GROUP_LIMIT		=> 'List the number exceeds the limit',
		self::API_EC_LISTS_EXIST_USER_ID	=> 'This user has been on the list',
		self::API_EC_LISTS_NOT_EXIST_USER	=> 'The user is not in the list',
		self::API_EC_LISTS_NOT_EXIST		=> 'A list of the user does not exist',
		self::API_EC_LISTS_ALREADY_EXIST	=> 'The list already exist',
			
		self::API_EC_ACCOUNT_LOGINFAILED 	=> 'Logon authentications failed',
		self::API_EC_ACOUNT_AUTHCODE_FAIL 	=> 'Authcode validation failed',
		self::API_EC_ACOUNT_LOGIN_BANNED 	=> 'Login temporarily banned',
		self::API_EC_ACOUNT_LIMIT_MMS 		=> 'Calls to limit of mms',
		self::API_EC_ACOUNT_PASSWD_ERROR 	=> 'Password error',
		self::API_EC_ACOUNT_AUTHCODE_ERROR	=> 'Authcode error',

		self::API_EC_MEDAL_EMPTY_MEDALID	=> 'Medal ID can not be empty',
		self::API_EC_MEDAL_AWARDED			=> 'The user has won the medal',
		self::API_EC_MEDAL_CANT_SUSPEND		=> 'This medal can not suspend',

	);

	/**
	 * 获取状态码说明
	 * @param $errno
	 */
	public static function GetErrorDescriptor($errno) {
		if( isset(self::$api_error_descriptions[$errno]) ) {
			return self::$api_error_descriptions[$errno];
		} else {
			return '';
		}
	}
}
